/*
 * StaticsPanel.java
 *
 * Created on 2008年6月9日, 上午12:28
 */
package gui;

import abstractmodel.*;
import model.StatisticsInfo;

/**
 * show statistics according to input
 * @author  littlechild
 */
public class StaticsPanel extends javax.swing.JPanel {

    Object o;

    /** Creates new form StaticsPanel 
     * 
     */
    public StaticsPanel(Object obj) {
        o = obj;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statisticPanelComboBox = new javax.swing.JComboBox();
        chartPanel = new javax.swing.JPanel();

        statisticPanelComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "曲线图", "饼图", "直方图" }));
        statisticPanelComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statisticPanelComboBoxActionPerformed(evt);
            }
        });

        chartPanel.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(181, 181, 181)
                .addComponent(statisticPanelComboBox, 0, 115, Short.MAX_VALUE)
                .addGap(199, 199, 199))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statisticPanelComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void statisticPanelComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statisticPanelComboBoxActionPerformed
    // 0：曲线图  1：饼图  2：直方图
    int index = this.statisticPanelComboBox.getSelectedIndex();
    System.out.println(index + "");
    StatisticsInfo stinfo;
    this.chartPanel.removeAll();
    switch (index) {
        case 0:
            if (o instanceof IUser) {
                stinfo = ((IUser)o).getStatistics(StatisticsType.LINE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.LINE), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IBook) {
                stinfo = ((IBook)o).getStatistics(StatisticsType.LINE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.LINE), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IAccount) {
                stinfo = ((IAccount)o).getStatistics(StatisticsType.LINE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.LINE), java.awt.BorderLayout.CENTER);
            }
            break;
        case 1:
            if (o instanceof IUser) {
                stinfo = ((IUser)o).getStatistics(StatisticsType.PIE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.PIE), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IBook) {
                stinfo = ((IBook)o).getStatistics(StatisticsType.PIE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.PIE), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IAccount) {
                stinfo = ((IAccount)o).getStatistics(StatisticsType.PIE);
                this.chartPanel.add(stinfo.getChart(StatisticsType.PIE), java.awt.BorderLayout.CENTER);
            }
            break;
        case 2:
            if (o instanceof IUser) {
                stinfo = ((IUser)o).getStatistics(StatisticsType.HISTOGRAM);
                this.chartPanel.add(stinfo.getChart(StatisticsType.HISTOGRAM), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IBook) {
                stinfo = ((IBook)o).getStatistics(StatisticsType.HISTOGRAM);
                this.chartPanel.add(stinfo.getChart(StatisticsType.HISTOGRAM), java.awt.BorderLayout.CENTER);
            } else if (o instanceof IAccount) {
                stinfo = ((IAccount)o).getStatistics(StatisticsType.HISTOGRAM);
                this.chartPanel.add(stinfo.getChart(StatisticsType.HISTOGRAM), java.awt.BorderLayout.CENTER);
            }      
            break;
    }
    this.updateUI();
}//GEN-LAST:event_statisticPanelComboBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel chartPanel;
    private javax.swing.JComboBox statisticPanelComboBox;
    // End of variables declaration//GEN-END:variables
}
